package com.xc.hotelmgr.datapusherali.controller;

import com.xc.hotelmgr.datapusherali.pojo.mq.HotelCallBack;
import com.xc.hotelmgr.datapusherali.pojo.mq.SendAll;
import com.xc.hotelmgr.datapusherali.pojo.mq.UpDown;
import com.xc.hotelmgr.datapusherali.service.fz.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther dy
 * @date 2020/8/31 17:32
 */

@RestController
@RequestMapping("/hotel")
public class FzHotelController {

    @Autowired
    private HotelService hotelService;

    // 酒店推送（监测动态变化使用/推送所有分销商店铺）ok
    @RequestMapping(value = "/send_update_hotel", method = RequestMethod.POST)
    public String hotelSendUpdate(@RequestBody HotelCallBack hotelCallBack) {
        hotelService.callBackHotel(hotelCallBack);
        return "ok";
    }

    /**
     * 推送指定店面下的酒店，酒店上线（店铺主动推送/包括房型价格计划，价格）（分销商使用）
     * @param sendAll
     * @return
     */
    @RequestMapping(value = "/send_all", method = RequestMethod.POST)
    public String hotelAllSend(@RequestBody SendAll sendAll) throws InterruptedException {
        int storeId = sendAll.getStoreId();
        Long hotelId = sendAll.getHotelId();
        Long taskId = sendAll.getTaskId();
        String appKey = sendAll.getAppKey();
        String sessionKey = sendAll.getSessionKey();
        String secret = sendAll.getSecret();
        Integer sendType = sendAll.getSendType();
        //全部推送
        if(sendType == -1) {
            hotelService.AllSend(storeId, hotelId, taskId, appKey, secret, sessionKey);
        }
        //只推送rp
        else {
            hotelService.rpSend(storeId, hotelId, taskId, appKey, secret, sessionKey,sendType);
        }
        return "ok";
    }

    /**
     * 酒店上下架、删除（前端调用）
     * @param upDown
     * @return
     */
    @RequestMapping(value = "/state", method = RequestMethod.POST)
    public String hotelSend(@RequestBody UpDown upDown) {
        int storeId = upDown.getStoreId();
        Long hotelId = upDown.getHotelId();
        int status = upDown.getStatus();
        Long taskId = upDown.getTaskId();
        String appKey = upDown.getAppKey();
        String sessionKey = upDown.getSessionKey();
        String secret = upDown.getSecret();
        if(status!=-1) {
            hotelService.hotelUpDown(storeId, hotelId, status, taskId, appKey, secret, sessionKey);
        }else {
            hotelService.allDelete(storeId, hotelId, taskId, appKey, secret, sessionKey);
        }
        return "ok";
    }
}
